package homework;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Scanner;

public class Test08 {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String name = scanner.nextLine();
        System.out.println("请输入密码:");
        String pwd = scanner.nextLine();
        System.out.println("请输入昵称:");
        String nick = scanner.nextLine();
        System.out.println("请输入年龄:");
        int age = scanner.nextInt();
        if (name == null || name.isEmpty() || pwd == null || pwd.isEmpty() || nick == null || nick.isEmpty() || !name.matches("\\w{1,32}")) {
            System.out.println("输入信息有误");
            return;
        }
        User user = new User(name, pwd, nick, age);
        FileOutputStream fos = new FileOutputStream(name + ".obj");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(user);
        System.out.println("注册完毕!");
        oos.close();
    }
}
